package com.lotusfall.jdbc;

import java.sql.*;
import java.util.Scanner;

//
public class JDBCTest09 {
    public static void main(String[] args) {
        // 执行SQL
        Connection conn = null;
        PreparedStatement ps = null;

        try {
            // 1、注册驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            // 2、获取链接
            String url = "jdbc:mysql://127.0.0.1:3306/learn?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
            String user = "root";
            String password = "994695";
            conn = DriverManager.getConnection(url,user,password);

            // 3、获取预编译的数据库操作对象
            // String sql = "insert into dept(deptno,dname,loc) values(?,?,?)";
            // String sql = "update dept set dname = ?,loc = ? where deptno = ?";
            String sql = "delete from dept where deptno = ?";
            ps = conn.prepareStatement(sql);
            // 4、执行sql语句
//            ps.setInt(1,60);
//            ps.setString(2,"销售部");
//            ps.setString(3,"上海");

/*          ps.setString(1,"研发部");
            ps.setString(2,"北京");
            ps.setInt(3,60);
            */


            ps.setInt(1,60);

            int count = ps.executeUpdate();
            System.out.println(count);
            // 5、处理结果集
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
        }finally {
            if(ps!=null){
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
